package cli.menu;


class AlertSettings extends Function {

public static State runMenu() {
		
State nextState = State.ALERTSETTINGS;
String input = null;

while(input == null || input.length() == 0){
		cli.println("-= Main menu > Alert Settings =-");
		cli.println("[b]: back [u]: undo [r]: redo [h]: home menu");
		cli.println("");
		cli.println("1. Change the minimum acceptable balance");
		cli.println("2. Change the number of days left for repayment");
		cli.println("");
		cli.println("Please enter your option: ");
		input = cli.nextLine();
		cli.clearScreen();
}

	if(input.length() == 1){
		char charInput = input.charAt(0);

		switch (charInput) {
		case '1':
			changeBalanceLimit();
			break;
		case '2':
			changeDaysLeftToPayment();
			break;
		case 'u':
		case 'U':
			tools.undo();
			break;
		case 'r':
		case 'R':
			tools.redo();
			break;
		case 'b':
		case 'B':
		case 'h':
		case 'H':
			nextState = State.MAINMENU;
		default:
			cli.println("Invalid Input");
			break;
		}
	}
	
	else{
		cli.println("Invalid input: " + input);
	}
	
	return nextState;
	}

	protected static void changeBalanceLimit() {
		double oldSetting = cli.getApi().getMinBalance();
		oldSetting /= 100;
	
		String input = null;
		
		while(input == null || input.length() == 0){
			cli.println("Your current setting - > Alert when balance is below: $"
					+ oldSetting);
			cli.println("Enter your new value: ");
		input = cli.nextLine();
		cli.clearScreen();
		}
	
		int amount = tools.Money2int(input);
		cli.getApi().setMinBalance(amount);
	}

	protected static void changeDaysLeftToPayment() {
		int oldSetting = cli.getApi().getDaysToPayment();

	
	
		String input = null;
		while(input == null || input.length() == 0){
		cli.println("Your current setting - > Alert when days to loan payments is within: "
				+ oldSetting + " Days");
		cli.println("Enter your new value: ");
		input = cli.nextLine();
		cli.clearScreen();
		}
	
		int days = Integer.valueOf(input);

		cli.getApi().setDaysToPayment(days);
	}

}